package com.mediastory.spsserver.logging.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mediastory.spsserver.advertising.domain.Advertising;
import com.mediastory.spsserver.advertising.service.AdvertisingSvc;
import com.mediastory.spsserver.category.service.CategorySvc;
import com.mediastory.spsserver.content.domain.Content;
import com.mediastory.spsserver.content.service.ContentSvc;
import com.mediastory.spsserver.event.domain.Event;
import com.mediastory.spsserver.event.service.EventSvc;
import com.mediastory.spsserver.gcm.domain.Gcm;
import com.mediastory.spsserver.gcm.service.GcmSvc;
import com.mediastory.spsserver.logging.service.LoggingSvc;
import com.mediastory.spsserver.notice.domain.Notice;
import com.mediastory.spsserver.notice.service.NoticeSvc;

/**
 * @author Jaewon Choi
 */

@Controller
@RequestMapping(value={"/logging"})
public class LoggingCtrl {
	
	private final Logger logger = Logger.getLogger(getClass());

	@Autowired
	private LoggingSvc loggingSvc;
	
	@Autowired
	private ContentSvc contentSvc;
	
	@Autowired
	private GcmSvc gcmSvc;
	
	@Autowired
	private NoticeSvc noticeSvc;

	@Autowired
	private EventSvc eventSvc;
	
	@Autowired
	private AdvertisingSvc advertisingSvc;
	
	@Autowired
	private CategorySvc categorySvc;

	/**
	 * 카테고리 통계
	 * */
	@RequestMapping(value={"/category.do"})
	public Map<String, Object> category(HttpServletRequest request) throws Exception {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("categoryList", categorySvc.findbyList(null));

		return resultMap;
	}
	
	/**
	 * 카테고리 통계 데이터
	 * */
	@RequestMapping(value={"/getCateData.do"})
	public Map<String, Object> getCateData(HttpServletRequest request, HttpSession session) throws Exception {
		Map<String, Object> condition = new HashMap<String, Object>();
		
		Integer cIdx = (Integer)session.getAttribute("cIdx");
		
		//검색 parameter
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String categoryId = ServletRequestUtils.getStringParameter(request, "categoryId");

		condition.put("cIdx", cIdx);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("categoryId", categoryId);
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("loggingList", loggingSvc.findbyListCategory(condition));
		
		return resultMap;
	}
	
	/**
	 * 앱 통계
	 * */
	@RequestMapping(value={"/app.do"})
	public void app() throws Exception {}
	
	/**
	 * 앱 통계 데이터
	 * */
	@RequestMapping(value={"/getAppData.do"})
	public Map<String, Object> getAppData(HttpServletRequest request, HttpSession session) throws Exception {
		Map<String, Object> condition = new HashMap<String, Object>();
		
		Integer cIdx = (Integer)session.getAttribute("cIdx");
		
		//검색 parameter
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String appId = ServletRequestUtils.getStringParameter(request, "appId");
		String userType = ServletRequestUtils.getStringParameter(request, "userType");

		condition.put("cIdx", cIdx);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("appId", appId);
		condition.put("userType", userType);
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("loggingList", loggingSvc.findbyListApp(condition));
		
		return resultMap;
	}
	
	/**
	 * 앱타입 통계
	 * */
	@RequestMapping(value={"/appId.do"})
	public Map<String, Object> appId(HttpServletRequest request, HttpSession session) throws Exception {
		Map<String, Object> condition = new HashMap<String, Object>();
		
		Integer cIdx = (Integer)session.getAttribute("cIdx");
		
		//검색 parameter
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String categoryId = ServletRequestUtils.getStringParameter(request, "categoryId");
		
		condition.put("cIdx", cIdx);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("categoryId", categoryId);
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("loggingList", loggingSvc.findbyListAppId(condition));
		resultMap.put("categoryList", categorySvc.findbyList(null));
		
		return resultMap;
	}
	
	/**
	 * 프로토콜버전 통계
	 * */
	@RequestMapping(value={"/protocolVer.do"})
	public Map<String, Object> protocolVer(HttpServletRequest request) throws Exception {
		Map<String, Object> condition = new HashMap<String, Object>();
		//검색 parameter
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String categoryId = ServletRequestUtils.getStringParameter(request, "categoryId");
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("categoryId", categoryId);
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("loggingList", loggingSvc.findbyListProtocolVer(condition));
		resultMap.put("categoryList", categorySvc.findbyList(null));
		
		return resultMap;
	}
	
	/**
	 * 콘텐츠 통계
	 * */
	@RequestMapping(value={"/content.do"})
	public Map<String, Object> content(HttpServletRequest request) throws Exception {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("categoryList", categorySvc.findbyList(null));
		
		return resultMap;
	}
	
	/**
	 * 콘텐츠 통계 데이터
	 * */
	@RequestMapping(value={"/getContData.do"})
	public Map<String, Object> getContData(HttpServletRequest request, HttpSession session) throws Exception {
		Map<String, Object> condition = new HashMap<String, Object>();
		
		Integer cIdx = (Integer)session.getAttribute("cIdx");
		
		//검색 parameter
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String contNm = ServletRequestUtils.getStringParameter(request, "contNm");
		String categoryId = ServletRequestUtils.getStringParameter(request, "categoryId");

		condition.put("cIdx", cIdx);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("contNm", contNm);
		condition.put("categoryId", categoryId);
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("loggingList", loggingSvc.findbyListContent(condition));
		
		return resultMap;
	}
	
	/**
	 * 콘텐츠 상세 사용 횟수 통계
	 * */
	@RequestMapping(value={"/contDetail.do"})
	public Map<String, Object> contDetail(HttpServletRequest request) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		Map<String, Object> condition = new HashMap<String, Object>();
		List<Content> contentList = contentSvc.findbyList(condition);
		resultMap.put("contentList", contentList);
		
		//검색 parameter
		Integer contIdx = ServletRequestUtils.getIntParameter(request, "contIdx", contentList.get(0).getIdx());
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		Integer startPage = ServletRequestUtils.getIntParameter(request, "startPage", 0);
		Integer endPage = ServletRequestUtils.getIntParameter(request, "endPage", 0);
		condition.put("contIdx", contIdx);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("startPage", startPage);
		condition.put("endPage", endPage);
		
		resultMap.put("loggingList", loggingSvc.findbyListContDetail(condition));
		
		return resultMap;
	}
	
	/**
	 * 콘텐츠 상세 사용 횟수 통계
	 * */
	@RequestMapping(value={"/getContDetailData.do"})
	public Map<String, Object> getContDetailData(HttpServletRequest request) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		Map<String, Object> condition = new HashMap<String, Object>();
		
		//검색 parameter
		Integer contId = ServletRequestUtils.getIntParameter(request, "contId");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		Integer startPage = ServletRequestUtils.getIntParameter(request, "startPage", 0);
		Integer endPage = ServletRequestUtils.getIntParameter(request, "endPage", 0);
		condition.put("contId", contId);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("startPage", startPage);
		condition.put("endPage", endPage);
		
		resultMap.put("loggingList", loggingSvc.findbyListContDetail(condition));
		
		return resultMap;
	}
	
	/**
	 * 페이지 내 유닛 사용 횟수 통계
	 * */
	@RequestMapping(value={"/getPageData.do"})
	public Map<String, Object> getPageData(HttpServletRequest request) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		Map<String, Object> condition = new HashMap<String, Object>();
		
		//검색 parameter
		Integer contId = ServletRequestUtils.getIntParameter(request, "contId");
		Integer pageNum = ServletRequestUtils.getIntParameter(request, "pageNum");
		condition.put("contId", contId);
		condition.put("pageNum", pageNum);
		
		resultMap.put("loggingList", loggingSvc.findbyListPage(condition));
		
		return resultMap;
	}
	
	/**
	 * 통합 통계
	 * */
	@RequestMapping(value={"/grp.do"})
	public Map<String, Object> getGrp(HttpServletRequest request) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		Map<String, Object> condition = new HashMap<String, Object>();
		
		//검색 parameter
		String logType = ServletRequestUtils.getStringParameter(request, "logType");
		String grp = ServletRequestUtils.getStringParameter(request, "grp");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String type = ServletRequestUtils.getStringParameter(request, "type");
		condition.put("logType", logType);
		condition.put("grp", grp);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("type", type);
		if(logType != null && ! logType.equals("")){
			resultMap.put("logData", loggingSvc.findbyListGrp(condition));
		}
		
		condition = new HashMap<String, Object>();
		
		//콘텐츠 목록
		List<Content> contentList = contentSvc.findbyList(condition);
		resultMap.put("contentList", contentList);
		
		//푸시 메시지 목록
		List<Gcm> gcmList = gcmSvc.findbyList(condition);
		resultMap.put("gcmList", gcmList);
		
		//긴급공지 목록
		List<Notice> noticeList = noticeSvc.findbyList(condition);
		resultMap.put("noticeList", noticeList);
		
		//이벤트 목록
		List<Event> eventList = eventSvc.findbyList(condition);
		resultMap.put("eventList", eventList);
		
		//광고 목록
		List<Advertising> advertisingList = advertisingSvc.findbyList(condition);
		resultMap.put("advertisingList", advertisingList);
		
		return resultMap;
	}
	

	/**
	 * 앱시작 횟수
	 * */
	@RequestMapping(value={"/appLifeCycle.do"})
	public Map<String, Object> getAppLifeCycle(HttpServletRequest request) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> condition = new HashMap<String, Object>();

		//검색 parameter
		String osGubun = ServletRequestUtils.getStringParameter(request, "osGubun");
		String model = ServletRequestUtils.getStringParameter(request, "model");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String type = ServletRequestUtils.getStringParameter(request, "type");
		String check = "N";
		
		if(osGubun != null && osGubun.equals("all")) {
			osGubun = "";
			check = "Y";
		}
		if(model != null && model.equals("all")) {
			model = "";
		}

		condition.put("osGubun", osGubun);
		condition.put("model", model);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("type", type);

		if((osGubun != null && !osGubun.equals("")) || check.equals("Y")){
			resultMap.put("logData", loggingSvc.findbyListAppLifeCycle(condition));
		}
		
		//기종 목록(android)
		condition.put("osGubun", "android");
		resultMap.put("androidModelList", loggingSvc.findbyModelList(condition));
		
		//기종 목록(ios)
		condition.put("osGubun", "ios");
		resultMap.put("iosModelList", loggingSvc.findbyModelList(condition));
		
		return resultMap;
	}
	
	/**
	 * 잡지 다운로드
	 * */
	@RequestMapping(value={"/downCont.do"})
	public Map<String, Object> getDownCont(HttpServletRequest request,  HttpSession session) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> condition = new HashMap<String, Object>();

		//검색 parameter
		String osGubun = ServletRequestUtils.getStringParameter(request, "osGubun");
		String model = ServletRequestUtils.getStringParameter(request, "model");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String type = ServletRequestUtils.getStringParameter(request, "type");
		String networkType = ServletRequestUtils.getStringParameter(request, "networkType");
		Integer contIdx = ServletRequestUtils.getIntParameter(request, "contIdx");
		String check = "N";
		
		if(osGubun != null && osGubun.equals("all")) {
			osGubun = "";
			check = "Y";
		}
		if(model != null && model.equals("all")) {
			model = "";
		}
		if(networkType != null && networkType.equals("all")) {
			networkType = "";
		}

		condition.put("osGubun", osGubun);
		condition.put("model", model);
		condition.put("networkType", networkType);
		condition.put("contIdx", contIdx);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("type", type);
		
		if((osGubun != null && !osGubun.equals("")) || check.equals("Y")){
			resultMap.put("logData", loggingSvc.findbyListDownCont(condition));
		}
		
		String userRole = (String)session.getAttribute("userRole");
		//customerIdx		
		Integer cIdx = (Integer)session.getAttribute("cIdx");
		if(!userRole.equals("ROLE_ADMIN")) {
			condition.put("cIdx", cIdx);
		}
		//콘텐츠 목록		
		List<Content> contentList = contentSvc.findbyList(condition);
		resultMap.put("contentList", contentList);
		
		//기종 목록(android)
		condition.put("osGubun", "android");
		resultMap.put("androidModelList", loggingSvc.findbyModelList(condition));
		
		//기종 목록(ios)
		condition.put("osGubun", "ios");
		resultMap.put("iosModelList", loggingSvc.findbyModelList(condition));
				
		return resultMap;
	}
	
	/**
	 * 푸시 메시지 확인 횟수
	 * */
	@RequestMapping(value={"/confirmPush.do"})
	public Map<String, Object> getConfirmPush(HttpServletRequest request) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> condition = new HashMap<String, Object>();

		//검색 parameter
		String osGubun = ServletRequestUtils.getStringParameter(request, "osGubun");
		String model = ServletRequestUtils.getStringParameter(request, "model");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String check = "N";
		
		if(osGubun != null && osGubun.equals("all")) {
			osGubun = "";
			check = "Y";
		}
		if(model != null && model.equals("all")) {
			model = "";
		}

		condition.put("osGubun", osGubun);
		condition.put("model", model);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);

		if((osGubun != null && !osGubun.equals("")) || check.equals("Y")){
			resultMap.put("logData", loggingSvc.findbyListConfirmPush(condition));
		}
		
		//기종 목록(android)
		condition.put("osGubun", "android");
		resultMap.put("androidModelList", loggingSvc.findbyModelList(condition));
		
		//기종 목록(ios)
		condition.put("osGubun", "ios");
		resultMap.put("iosModelList", loggingSvc.findbyModelList(condition));
				
		return resultMap;
	}
	
	/**
	 * 긴급공지 조회수
	 * */
	@RequestMapping(value={"/confirmNotice.do"})
	public Map<String, Object> getConfirmNotice(HttpServletRequest request) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> condition = new HashMap<String, Object>();

		//검색 parameter
		String osGubun = ServletRequestUtils.getStringParameter(request, "osGubun");
		String model = ServletRequestUtils.getStringParameter(request, "model");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String check = "N";
		
		if(osGubun != null && osGubun.equals("all")) {
			osGubun = "";
			check = "Y";
		}
		if(model != null && model.equals("all")) {
			model = "";
		}

		condition.put("osGubun", osGubun);
		condition.put("model", model);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);

		if((osGubun != null && !osGubun.equals("")) || check.equals("Y")){
			resultMap.put("logData", loggingSvc.findbyListConfirmNotice(condition));
		}
		
		//기종 목록(android)
		condition.put("osGubun", "android");
		resultMap.put("androidModelList", loggingSvc.findbyModelList(condition));
		
		//기종 목록(ios)
		condition.put("osGubun", "ios");
		resultMap.put("iosModelList", loggingSvc.findbyModelList(condition));
				
		return resultMap;
	}
	
	/**
	 * 앱 업데이트 시도 횟수
	 * */
	@RequestMapping(value={"/appUpdate.do"})
	public Map<String, Object> getAppUpdate(HttpServletRequest request) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> condition = new HashMap<String, Object>();

		//검색 parameter
		String osGubun = ServletRequestUtils.getStringParameter(request, "osGubun");
		String model = ServletRequestUtils.getStringParameter(request, "model");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String check = "N";
		
		if(osGubun != null && osGubun.equals("all")) {
			osGubun = "";
			check = "Y";
		}
		if(model != null && model.equals("all")) {
			model = "";
		}

		condition.put("osGubun", osGubun);
		condition.put("model", model);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);

		if((osGubun != null && !osGubun.equals("")) || check.equals("Y")){
			resultMap.put("logData", loggingSvc.findbyListAppUpdate(condition));
		}
		
		//기종 목록(android)
		condition.put("osGubun", "android");
		resultMap.put("androidModelList", loggingSvc.findbyModelList(condition));
		
		//기종 목록(ios)
		condition.put("osGubun", "ios");
		resultMap.put("iosModelList", loggingSvc.findbyModelList(condition));
				
		return resultMap;
	}
	
	/**
	 * 이벤트 조회 횟수
	 * */
	@RequestMapping(value={"/detailedEvent.do"})
	public Map<String, Object> getDetailedEvent(HttpServletRequest request) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> condition = new HashMap<String, Object>();

		//검색 parameter
		String osGubun = ServletRequestUtils.getStringParameter(request, "osGubun");
		String model = ServletRequestUtils.getStringParameter(request, "model");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String eventIdx = ServletRequestUtils.getStringParameter(request, "eventIdx");
		String check = "N";
		
		if(osGubun != null && osGubun.equals("all")) {
			osGubun = "";
			check = "Y";
		}
		if(model != null && model.equals("all")) {
			model = "";
		}

		condition.put("osGubun", osGubun);
		condition.put("model", model);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("eventIdx", eventIdx);

		if((osGubun != null && !osGubun.equals("")) || check.equals("Y")){
			resultMap.put("logData", loggingSvc.findbyListDetailedEvent(condition));
		}
		
		//이벤트 목록
		List<Event> eventList = eventSvc.findbyList(condition);
		resultMap.put("eventList", eventList);
		
		//기종 목록(android)
		condition.put("osGubun", "android");
		resultMap.put("androidModelList", loggingSvc.findbyModelList(condition));
		
		//기종 목록(ios)
		condition.put("osGubun", "ios");
		resultMap.put("iosModelList", loggingSvc.findbyModelList(condition));
				
		return resultMap;
	}
	
	/**
	 * 광고클릭 횟수
	 * */
	@RequestMapping(value={"/adClick.do"})
	public Map<String, Object> getAdClick(HttpServletRequest request) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> condition = new HashMap<String, Object>();

		//검색 parameter
		String osGubun = ServletRequestUtils.getStringParameter(request, "osGubun");
		String model = ServletRequestUtils.getStringParameter(request, "model");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String adIdx = ServletRequestUtils.getStringParameter(request, "adIdx");
		String check = "N";
		
		if(osGubun != null && osGubun.equals("all")) {
			osGubun = "";
			check = "Y";
		}
		if(model != null && model.equals("all")) {
			model = "";
		}

		condition.put("osGubun", osGubun);
		condition.put("model", model);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("adIdx", adIdx);

		if((osGubun != null && !osGubun.equals("")) || check.equals("Y")){
			resultMap.put("logData", loggingSvc.findbyListAdClick(condition));
		}		
		
		//광고 목록
		List<Advertising> advertisingList = advertisingSvc.findbyList(condition);
		resultMap.put("advertisingList", advertisingList);
		
		//기종 목록(android)
		condition.put("osGubun", "android");
		resultMap.put("androidModelList", loggingSvc.findbyModelList(condition));
		
		//기종 목록(ios)
		condition.put("osGubun", "ios");
		resultMap.put("iosModelList", loggingSvc.findbyModelList(condition));
				
		return resultMap;
	}
	
	/**
	 * 잡지 읽기 횟수
	 * */
	@RequestMapping(value={"/viewCont.do"})
	public Map<String, Object> getViewCont(HttpServletRequest request, HttpSession session) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> condition = new HashMap<String, Object>();

		//검색 parameter
		String osGubun = ServletRequestUtils.getStringParameter(request, "osGubun");
		String model = ServletRequestUtils.getStringParameter(request, "model");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String contIdx = ServletRequestUtils.getStringParameter(request, "contIdx");
		String check = "N";
		
		if(osGubun != null && osGubun.equals("all")) {
			osGubun = "";
			check = "Y";
		}
		if(model != null && model.equals("all")) {
			model = "";
		}

		condition.put("osGubun", osGubun);
		condition.put("model", model);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("contIdx", contIdx);

		if((osGubun != null && !osGubun.equals("")) || check.equals("Y")){
			resultMap.put("logData", loggingSvc.findbyListViewCont(condition));
		}
		
		String userRole = (String)session.getAttribute("userRole");
		//customerIdx		
		Integer cIdx = (Integer)session.getAttribute("cIdx");
		if(!userRole.equals("ROLE_ADMIN")) {
			condition.put("cIdx", cIdx);
		}
		//콘텐츠 목록
		List<Content> contentList = contentSvc.findbyList(condition);
		resultMap.put("contentList", contentList);
		
		//기종 목록(android)
		condition.put("osGubun", "android");
		resultMap.put("androidModelList", loggingSvc.findbyModelList(condition));
		
		//기종 목록(ios)
		condition.put("osGubun", "ios");
		resultMap.put("iosModelList", loggingSvc.findbyModelList(condition));
				
		return resultMap;
	}
	
	/**
	 * 잡지 상세설명 조회 횟수
	 * */
	@RequestMapping(value={"/detailCont.do"})
	public Map<String, Object> getDetailCont(HttpServletRequest request, HttpSession session) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> condition = new HashMap<String, Object>();

		//검색 parameter
		String osGubun = ServletRequestUtils.getStringParameter(request, "osGubun");
		String model = ServletRequestUtils.getStringParameter(request, "model");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String contIdx = ServletRequestUtils.getStringParameter(request, "contIdx");
		String check = "N";
		
		if(osGubun != null && osGubun.equals("all")) {
			osGubun = "";
			check = "Y";
		}
		if(model != null && model.equals("all")) {
			model = "";
		}

		condition.put("osGubun", osGubun);
		condition.put("model", model);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("contIdx", contIdx);

		if((osGubun != null && !osGubun.equals("")) || check.equals("Y")){
			resultMap.put("logData", loggingSvc.findbyListDetailCont(condition));
		}
		
		String userRole = (String)session.getAttribute("userRole");
		//customerIdx		
		Integer cIdx = (Integer)session.getAttribute("cIdx");
		if(!userRole.equals("ROLE_ADMIN")) {
			condition.put("cIdx", cIdx);
		}
		//콘텐츠 목록
		List<Content> contentList = contentSvc.findbyList(condition);
		resultMap.put("contentList", contentList);
		
		//기종 목록(android)
		condition.put("osGubun", "android");
		resultMap.put("androidModelList", loggingSvc.findbyModelList(condition));
		
		//기종 목록(ios)
		condition.put("osGubun", "ios");
		resultMap.put("iosModelList", loggingSvc.findbyModelList(condition));
				
		return resultMap;
	}
	
	/**
	 * 뷰어 로그 관련
	 * */
	@RequestMapping(value={"/viewLogData.do"})
	public Map<String, Object> getViewContData(HttpServletRequest request, HttpSession session) throws Exception {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> condition = new HashMap<String, Object>();

		//검색 parameter
		String osGubun = ServletRequestUtils.getStringParameter(request, "osGubun");
		String model = ServletRequestUtils.getStringParameter(request, "model");
		String startDate = ServletRequestUtils.getStringParameter(request, "startDate");
		String endDate = ServletRequestUtils.getStringParameter(request, "endDate");
		String contIdx = ServletRequestUtils.getStringParameter(request, "contIdx");
		String pageIndex = ServletRequestUtils.getStringParameter(request, "pageIndex");
		String check = "N";
		
		if(osGubun != null && osGubun.equals("all")) {
			osGubun = "";
			check = "Y";
		}
		if(model != null && model.equals("all")) {
			model = "";
		}

		condition.put("osGubun", osGubun);
		condition.put("model", model);
		condition.put("startDate", startDate);
		condition.put("endDate", endDate);
		condition.put("contIdx", contIdx);
		condition.put("pageIndex", pageIndex);
		

		if((osGubun != null && !osGubun.equals("")) || check.equals("Y")){
			resultMap.put("logData", loggingSvc.findbyListViewLogData(condition));
		}
		
		String userRole = (String)session.getAttribute("userRole");
		//customerIdx		
		Integer cIdx = (Integer)session.getAttribute("cIdx");
		if(!userRole.equals("ROLE_ADMIN")) {
			condition.put("cIdx", cIdx);
		}
		//콘텐츠 목록
		List<Content> contentList = contentSvc.findbyList(condition);
		resultMap.put("contentList", contentList);
		
		//기종 목록(android)
		condition.put("osGubun", "android");
		resultMap.put("androidModelList", loggingSvc.findbyModelList(condition));
		
		//기종 목록(ios)
		condition.put("osGubun", "ios");
		resultMap.put("iosModelList", loggingSvc.findbyModelList(condition));
				
		return resultMap;
	}

}